package easy;

public class Solution_908 {
    public int smallestRangeI(int[] nums, int k) {
        if (nums.length<2) {
            return 0;
        }
        int min = Integer.MAX_VALUE, max = Integer.MIN_VALUE, maxSub = k << 1;
        for (int i = 0; i < nums.length; i++) {
            min = Math.min(min, nums[i]);
            max = Math.max(max, nums[i]);
        }
        int a = max -min;
        if (a <= maxSub) {
            return 0;
        } else {
            return a - maxSub;
        }
    }

    public static void main(String[] args) {
        Solution_908 model = new Solution_908();
        System.out.println(model.smallestRangeI(new int[]{0, 10}, 2));
        System.out.println(model.smallestRangeI(new int[]{1, 3, 6}, 3));
    }
}
